package com.usian.controller;

import com.usian.pojo.TbItem;
import com.usian.pojo.TbItemCat;
import com.usian.pojo.TbItemParam;
import com.usian.service.ItemService;
import com.usian.utils.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/service")
public class ItemController {
    @Autowired
    private ItemService itemService;

    /**查询商品信息
     * 根据商品id
     * @param itemId
     * @return
     */
    @RequestMapping("/item/selectItemInfo")
    public TbItem selectItemInfo(Long itemId){
        return this.itemService.selectItemInfo(itemId);
    }
    @RequestMapping("/item/selectTbItemAllByPage")
    public PageResult selectTbItemAllByPage(@RequestParam(value = "page",defaultValue = "1") String page, @RequestParam(value = "rows",defaultValue = "2") String rows){
        return itemService.selectTbItemAllByPage(page,rows);
    }
    @RequestMapping("/itemCategory/selectItemCategoryByParentId")
   public List<TbItemCat> selectItemCategoryByParentId(@RequestParam("id")Integer id){
        return  itemService.selectItemCategoryByParentId(id);
    }
    @RequestMapping("/itemParam/selectItemParamByItemCatId/{itemCatId}")
    public TbItemParam selectItemParamByItemCatId(@PathVariable("itemCatId") Integer itemCatId){
        return  itemService.selectItemParamByItemCatId(itemCatId);
    }
    @PostMapping("/item/insertTbItem")
    public Integer insertTbItem(@RequestBody TbItem tbItem,@RequestParam("desc") String desc,@RequestParam("itemParams") String itemParams){
        return itemService.insertTbItem(tbItem,desc,itemParams);
    }
    @RequestMapping("/item/preUpdateItem")
    public Map<String, Object> preUpdateItem(Long itemId){
        return itemService.preUpdateItem(itemId);
    }
    @RequestMapping("/item/deleteItemById")
   public Integer deleteItemById(Long itemId){
        return itemService.deleteItemById(itemId);
    }
    @RequestMapping("/item/updateTbItem")
    public Integer updateTbItem(@RequestBody TbItem tbItem,@RequestParam("desc") String desc,@RequestParam("itemParams") String itemParams){
        return itemService.updateTbItem(tbItem,desc,itemParams);
    }

}